package com.dyna.web.websocket.controller;

import com.dyna.web.websocket.WebSocketServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api("demo模块/websocket")
@RestController
@RequestMapping("/socket")
public class WebSocketController {

    @ApiOperation("给用户发送消息")
    @RequestMapping("/msg")
    public void msg(@RequestParam("uid") Integer uid, @RequestParam("msg") String msg) {
        WebSocketServer webSocketServer = new WebSocketServer();
        webSocketServer.sendInfo(msg, uid);
    }

    @ApiOperation("给多个用户发送消息")
    @RequestMapping("/sendMassMsg")
    public void sendMassMsg(@RequestBody List<Integer> uidList, @RequestParam("msg") String msg) {
        WebSocketServer webSocketServer = new WebSocketServer();
        webSocketServer.sendInfo(msg, uidList);
    }

}
